package com.zhangxin.aiInterview.manager.redis.stress_detector;
import com.zhangxin.aiInterview.manager.python_api.PythonApi;
import com.zhangxin.aiInterview.model.enums.InterviewTypeEnum;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Objects;


/**
 * 消息生产者
 */
@Component
@AllArgsConstructor
public class StressDetectionProducer {
    private final StringRedisTemplate redisTemplate;
    private final PythonApi pythonApi;

    /**
     * 调用python接口进行压力值检测
     * @param userId
     * @param localAudioUrl 本地音频url
     * @param interviewType 面试类型
     */
    public void sendDetectionTask(Long userId, String localAudioUrl, Integer interviewType) {
        //技术面
        if(Objects.equals(interviewType, InterviewTypeEnum.TEC_INTERVIEW.getValue())){
            String queueKey = "AI_interview:tec_interview:stress_detector:" + userId;
            //调用接口获得压力值
            String result = pythonApi.lieCheck(localAudioUrl);
            //放入消息队列
            redisTemplate.opsForList().leftPush(queueKey, result);
            System.out.println("[生产者] 压力值已发送消息到队列 " + queueKey + ": " + result);
        }else {
            String queueKey = "AI_interview:hr_interview:stress_detector:" + userId;
            //调用接口
            String result = pythonApi.lieCheck(localAudioUrl);
            //放入消息队列
            redisTemplate.opsForList().leftPush(queueKey, result);
        }
    }

    public static void main(String[] args) {

    }
}